/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.stat;

import android.content.Context;
import android.text.TextUtils;
import java.net.URLEncoder;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.json.JSONArray;
import org.json.JSONObject;

public class ab {
    private static String c = "QPlayer";
    public static m a = null;
    public static boolean b = false;

    public static void a(m paramm, boolean paramBoolean) {
        if (a == null)
            a = new m();
        if ((!(TextUtils.isEmpty(a.a))) && (!(TextUtils.isEmpty(paramm.a))) && (!(a.a.equals(paramm.a)))) {
            a.c = null;
            a = null;
            a = new m();
        }
        if (paramBoolean) {
            if (!(TextUtils.isEmpty(paramm.b))) {
                if (a.c == null)
                    a.c = new HashSet();
                a.c.add(paramm.b);
            }
        }
        else {
            a.a = paramm.a;
            a.d = paramm.d;
            a.e = paramm.e;
            a.f = paramm.f;
            a.g = paramm.g;
            a.h = paramm.h;
            a.i = paramm.i;
        }
        b = true;
    }

    public static void a() {
        b = false;
    }

    public static void a(Context paramContext) {
        if ((a == null) || (TextUtils.isEmpty(a.a)))
            return;
        t.a(paramContext, URLEncoder.encode(a.a), t.b(paramContext, URLEncoder.encode(a.a), 1L) + 1L);
    }

    public static int a(Context paramContext, String paramString) {
        String str = t.b(paramContext, "playlist", "");
        if (!(str.contains(paramString + ","))) {
            str = str + paramString + ",";
            t.a(paramContext, "playlist", str);
        }
        return str.split(",").length;
    }

    public static JSONObject b(Context paramContext) {
        JSONObject localJSONObject = null;
        try {
            if (a != null) {
                localJSONObject = new JSONObject();
                if (!(TextUtils.isEmpty(a.a))) {
                    localJSONObject.put("id", a.a);
                    long l = t.b(paramContext, URLEncoder.encode(a.a), 1L);
                    localJSONObject.put("ttimes", l);
                    if (1L == l)
                        localJSONObject.put("accNum", a(paramContext, URLEncoder.encode(a.a)));
                }
                if (a.c != null) {
                    Iterator localIterator = a.c.iterator();
                    JSONArray localJSONArray = new JSONArray();
                    while (localIterator.hasNext())
                        localJSONArray.put(localIterator.next());
                    localJSONObject.put("role", localJSONArray);
                }
                if (a.d != 0)
                    localJSONObject.put("age", a.d);
                if (a.e != 0)
                    localJSONObject.put("gender", a.e);
                if (!(TextUtils.isEmpty(a.f)))
                    localJSONObject.put("source", a.f);
                if (!(TextUtils.isEmpty(a.g)))
                    localJSONObject.put("rank", a.g);
                if (!(TextUtils.isEmpty(a.h)))
                    localJSONObject.put("server", a.h);
                if (!(TextUtils.isEmpty(a.i)))
                    localJSONObject.put("comment", a.i);
                localJSONObject.put("ts", a.j);
            }
        } catch (Exception localException) {
            x.a(c, localException);
        } catch (Error localError) {
            x.a(c, localError);
        }
        return localJSONObject;
    }
}